//
//  ExamineScreenViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/9.
//

#import "ExamineScreenViewController.h"
#import "ScreenTableViewCell.h"
#import "DTChoosePersonListShowView.h"
#import "YTSelectStringShowView.h"
#import "PersonInCchargeShowView.h"
#import "TemplateFoundDetailsModel.h"
#import "TimeFrameShowView.h"
#import "ExamineResultViewController.h"

@interface ExamineScreenViewController ()

@end

@implementation ExamineScreenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = KcolorHex(@"#FBFBFB");
    self.StatusBarColor = NO;
    UIView * topview = [UIView new];
    topview.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.height.offset(Knav_HeightX);
    }];
    
  
    
    MJWeakSelf
    UIView * backview = [UIView new].addClickBlock(^{
        [weakSelf popViewController];
    });
    [topview addSubview:backview];
    [backview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(44);
        make.left.bottom.offset(0);
        make.width.offset(kwt(120));
    }];
    
    
    
    UIImageView * leftimg = kimageView(@"left_black_path");
    [backview addSubview:leftimg];
    [leftimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.left.offset(kwt(10));
        make.centerY.offset(0);
    }];
    
    UILabel * leftlab = [DTKTool labelWithText:@"筛选" andFont:kCFont(18) andTextColor:KcolorHex(@"#333333")];
    [topview addSubview:leftlab];
    [leftlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.offset(0);
        make.centerY.offset(KTop/2);
    }];
    
    UIView * buttonview = [UIView new];
    buttonview.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:buttonview];
    [buttonview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.height.offset(kwt(63) + KSafeAreaBottomHeight);
    }];
    UIView * line = [UIView new];
    line.backgroundColor = KcolorHex(@"#ECECEC");
    [buttonview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.offset(0);
        make.height.offset(0.5);
    }];
    
    UIButton * qxbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qxbtn.backgroundColor = KcolorHex(@"#F0F2F4");
    [qxbtn setTitle:@"重置" forState:UIControlStateNormal];
    [qxbtn setTitleColor:KcolorHex(@"#5A6066") forState:UIControlStateNormal];
    qxbtn.titleLabel.font = kCFont(17);
    [DTKTool YJ:kwt(5) andView:qxbtn];
    [qxbtn addTarget:self action:@selector(leftBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [buttonview addSubview:qxbtn];
    [qxbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(48));
        make.width.offset(kwt(133));
        make.left.offset(kwt(15));
        make.top.offset(kwt(8));
    }];
    
    UIButton * qrbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    qrbtn.backgroundColor = [UIColor gradientColorWithSize:CGSizeMake(kwt(195), 1) direction:GradientColorDirectionLevel startColor:KcolorHex(@"#2892FE") endColor:KcolorHex(@"#0366FE")];
    [qrbtn setTitle:@"确定" forState:UIControlStateNormal];
    [qrbtn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    qrbtn.titleLabel.font = kCFont(17);
    [DTKTool YJ:kwt(5) andView:qrbtn];
    [qrbtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [buttonview addSubview:qrbtn];
    [qrbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.offset(kwt(48));
        make.width.offset(kwt(195));
        make.right.offset(kwt(-15));
        make.top.offset(kwt(8));
    }];
    
    
    [self.view addSubview:self.tableview];
    self.tableview.backgroundColor = KcolorHex(@"#FBFBFB");

    [self.tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(topview.mas_bottom);
        make.bottom.equalTo(buttonview.mas_top);
    }];
    
}


- (void)leftBtnClick{
    self.model.taskId = @"";
    self.model.taskIdName = @"";
    self.model.pondTissueId = @"";
    self.model.pondTissueIdName = @"";
    self.model.pondId = @"";
    self.model.pondIdName = @"";
    self.model.userName = @"";
    self.model.userNameName = @"";
    self.model.handover = @"";
    self.model.handoverName = @"";
    self.model.startTime = @"";
    self.model.endTime = @"";
//    self.model.status = 0;
    self.model.applyType = 0;
    [self.tableview reloadData];
    
}

- (void)rightBtnClick{
//    ExamineResultViewController * vc = [ExamineResultViewController new];
//    vc.model = self.model;
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 1){
        return kwt(95);
    } else {
        return kwt(95);
    }
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    if(indexPath.row == 1){
        ScreenTimeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ScreenTimeTableViewCell"];
        if (cell == nil) {
            cell = [[ScreenTimeTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ScreenTimeTableViewCell"];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
       MJWeakSelf
        [cell setName:@"申请时间" andStartTime:self.model.startTime andEndTime:self.model.endTime andBlock:^(NSString * _Nonnull StartTime, NSString * _Nonnull EndTime) {
            [TimeFrameShowView showviewWithTitle:@"申请时间" andStartTime:self.model.startTime andEndTime:self.model.endTime andRightBlock:^(NSString * _Nonnull StartTime, NSString * _Nonnull EndTime) {
                weakSelf.model.endTime = EndTime;
                weakSelf.model.startTime = StartTime;
                [weakSelf.tableview reloadData];
            } andCZBlock:^{
                weakSelf.model.endTime = @"";
                weakSelf.model.startTime = @"";
                [weakSelf.tableview reloadData];
            }];
        }];
        return cell ;

    }
    ScreenDXTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ScreenDXTableViewCell"];
    if (cell == nil) {
        cell = [[ScreenDXTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ScreenDXTableViewCell"];
    }
    MJWeakSelf
    [cell setName:@"审核类型" andState:self.model.applyType andBlock:^(int state) {
        weakSelf.model.applyType = state;
        [weakSelf.tableview reloadData];
    }];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell ;
}

@end
